class Solution {

    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        int slowIndex=0, fastIndex=0;
        while (fastIndex < n) {
            while (nums[slowIndex] == nums[fastIndex]) {
                fastIndex++;
                if (fastIndex == n) return slowIndex+1;
            }
            slowIndex++;
            nums[slowIndex] = nums[fastIndex];
        }
        return slowIndex+1;
    }

    public int removeDuplicates1(int[] nums) {
        int n = nums.length;
        int slowIndex=1;
        for (int fastIndex = 1; fastIndex < n; fastIndex++) {
            while (nums[slowIndex-1] != nums[fastIndex]) {
                nums[slowIndex++] = nums[fastIndex];
            }
        }
        return slowIndex;
    }

}